package com.liuyang.demo.wechat;

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialFileBatchGetResult;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNewsBatchGetResult;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import java.util.HashMap;
import java.util.Map;

@Slf4j
public class WeiXin {
    @Autowired
    private WxMpService wxMpService;
    /**
     * <pre>
     * 获取图文素材列表 并且下载
     * 详情请见: <a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738734&token=&lang=zh_CN">获取素材列表</a>
     * 接口url格式：https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=ACCESS_TOKEN
     * @param offset
     *            从全部素材的该偏移位置开始返回，0表示从第一个素材 返回
     * @param count
     *            返回素材的数量，取值在1到20之间
     * </pre>
     */
    public void materialNewsBatchGet(int offset, int count) throws Exception {
        WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = wxMpService.getMaterialService().materialNewsBatchGet(offset, count);
        WxMpMaterialFileBatchGetResult image = wxMpService.getMaterialService().materialFileBatchGet("image", offset, count);
    }

    public static void main(String[] args) {
        test();
    }

    private static void test() {
        Map<String, Object> params = new HashMap();
        params.put("type", "image");
        params.put("offset", 0);
        params.put("count", 20);
        System.out.println(JSON.toJSONString(params));
    }

}
